<?php
session_start();
require "lib/db.php";
require "lib/product-function.php";

if(isset($_POST['btnAddProduct'])){
	$productName = $_POST['txtProductName'];
	$subCategoryID = $_POST['cbSubCategoryName'];
	settype($subCategoryID,"int");
	$price = $_POST['txtPrice'];
	$unit = $_POST['txtUnit'];
	$image = $_POST['txtImage'];
	$description = $_POST['taDescription'];
	addProduct($productName,$subCategoryID,$price,$unit,$image,$description);
	header("location:list-product.php");
}

if(isset($_POST['btnEditProduct'])){
	$productName = $_POST['txtProductName'];
	$subCategoryID = $_POST['cbSubCategoryName'];
	settype($subCategoryID,"int");
	$price = $_POST['txtPrice'];
	$unit = $_POST['txtUnit'];
	$image = $_POST['txtImage'];
	$description = $_POST['taDescription'];
	$productID = $_POST['hfProductID'];
	settype($productID,"int");
	editProduct($productName,$subCategoryID,$price,$unit,$image,$description,$productID);
	header("location:list-product.php");
}
?>